Page({
  data: {
    avatarUrl: ''
  },
  onLoad() {
    const eventChannel = this.getOpenerEventChannel()
    eventChannel.on('acceptDataFromCenter', (data) => {
      this.setData({ avatarUrl: data.avatarUrl })
    })
  },
  chooseAvatar() {
    wx.chooseImage({
      count: 1,
      sizeType: ['original', 'compressed'],
      sourceType: ['album', 'camera'],
      success: (res) => {
        this.setData({ avatarUrl: res.tempFilePaths[0] })
      }
    })
  },
  saveAvatar() {
    const eventChannel = this.getOpenerEventChannel()
    eventChannel.emit('updateAvatar', { avatarUrl: this.data.avatarUrl })
    wx.navigateBack()
  }
})